﻿package com.projects.xenia;


import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.Map.Entry;

import com.projects.xenia.documents_classes.Documents_Order;
import com.projects.xenia.documents_classes.Documents_Order.DocLine;
import com.projects.xenia.global_modules.MainGlobalModule;
import com.projects.xenia.prompts_activities.Activity_NumericPrompt;
import com.projects.xenia.prompts_activities.Activity_OrderGoodsPrompt;
import com.projects.xenia.prompts_activities.Activity_ReturnGoodsPrompt;
import com.projects.xenia.ref_classes.GoodRefObject;
import com.projects.xenia.ref_classes.GoodsRefItem;
import com.projects.xenia.ref_classes.SalesRefItem;

import android.R.integer;
import android.app.AlertDialog;
import android.app.ListActivity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.opengl.Visibility;
import android.os.Bundle;
import android.os.Vibrator;


import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.SlidingDrawer;
import android.widget.TextView;
import android.widget.Toast;

 public class MainGoodsCatalogActivity extends ListActivity  {	
		 
	private EfficientAdapter adap;
	private ArrayAdapter<String> gadap;

	private static String DefGoodsGroup;
	
	private int DocType;	
	private String DocId;
	private String Firm;
	private String AccType;
	private String Department;	
	private String PriceCategory;
	private String Customer;	
	
	private boolean DiscountsEnable;
	
	private Object DocumentClass;	
	
	private Context Ctx;	
	
	private final int IDR_OrderGoodsPromptSelect = 1;
	private final int IDR_ReturnGoodsPromptSelect = 2;
	private final int IDR_Barcode = 3;
	private final int IDR_GoodsTreeSelect = 4;	
	private final int IDR_GoodsImagesSelect = 5;
	
	private final int IDR_NumericPromptCount = 6;
	private final int IDR_NumericPromptDistr = 7;

	private boolean SelectOnce = false;
	private boolean Hierarchy = true;
	
	private TextView OrderSumLabel;
	
	private ImageView order_root_iv;
	private ImageView order_barcode;
	private ImageView order_tree_iv;
	private ImageView order_AssortmentSelectOpen;	
	private ImageView presenter_btn;
	
	private Gallery GroupGallery;
	
	private ArrayList <GoodsRefItem> GoodsGroupList = new ArrayList<GoodsRefItem>();	
	private ArrayList <GoodsRefItem> GoodsRef;
	
	private GoodRefObject GoodObject;
	
	public HashMap<String, SalesRefItem> OrderSalesCollection;	
	public HashMap<String, GoodsRefItem> OrderAssortmentCollection;
	public HashMap<String, GoodsRefItem> CustomerAssortmentCollection;
	public HashMap<String, DocLine> OrderDocLineCollection;
	
	private String [] GoupArrayStrings = new String [] {""};
	
	private ImageView gds_backward;	

	private boolean GoodsRefRefresh;
	
	private ArrayList <String> OffersGoodsList;
	
	
	private String LastItem = "";
	private String LastParent = "";	
	
	private Button sel_pricecategory;
	private Button sel_sorting;	
	
	private String [] SelectedModeActions = new String [] {"Уст.кол-во","Распр.кол-во","Отобразить"}; 
	private String [] SortingItems = new String [] {"Наименование","Краткое наименование","Цена","Объем","Вес","Кратность"};	
	
	private Cursor PriceCategoryCursor;
	
	private LinkedHashMap <String,GoodsRefItem> SelectedGoods;
	
	//private ArrayList <GoodsRefItem> SelectedGoods;
	
	private boolean isSelectMode;
	
	private RelativeLayout actxLinear;
	private ImageView actxsetall;
	private ImageView actxunsetall;
	private ImageView actxunsetcount;
	private ImageView actxundistrcount;
	private ImageView actxundfilter;
	private ImageView actxundcancel;	
	
	LinkedHashMap<String, String> Assortments = new LinkedHashMap<String, String> ();
	
	private ImageView searchreset;
	private EditText searchprompt;
	private ImageView searchbutton;
	private SlidingDrawer slidingDrawer;
	
	private void GetPriceCategoryCursor () {
		
		PriceCategoryCursor = MainGlobalModule.DBE.rawQuery("select id as _id , descr from xref_pricecategory order by descr", null);
		
	}
	

	public String GetParent(String GoodsRef_ParentId) {
		
		String NewParentId;		
		Cursor Scalar = MainGlobalModule.DBE.rawQuery("SELECT parentid FROM xref_goods WHERE id = ?", new String []{GoodsRef_ParentId});
		Scalar.moveToFirst();
		NewParentId = Scalar.getString(0);
		return NewParentId;
		
	}	
		
	private void GetChildGoodsRefByGoodsIdNext (String GoodsId,boolean Append, boolean recursive) {		

		Cursor GoodsCursor = MainGlobalModule.GetGoodsRefCursorByParentId (GoodsId, PriceCategory, Firm, AccType, Department, GetSortingMode ());
			
		if (GoodsCursor.getCount() > 0){
			if (Append!=true){
				GoodsRef.clear();
			}				
			GoodsCursor.moveToFirst();				
			while (!GoodsCursor.isAfterLast()) {				
				GoodsRefItem gi = new GoodsRefItem ();
				gi.id = GoodsCursor.getString(0);
				gi.parentid = GoodsCursor.getString(1);
				gi.article = GoodsCursor.getString(2);
				gi.descr = GoodsCursor.getString(3);
				gi.isfolder = GoodsCursor.getInt(4);
				gi.weight = GoodsCursor.getDouble(5);
				gi.volume = GoodsCursor.getDouble(6);
				gi.minimum_order = GoodsCursor.getDouble(7);
				gi.price = GoodsCursor.getDouble(8);
				
				if (DiscountsEnable & gi.isfolder == 0) {
					double _price0 = GoodObject.GetGoodPriceByDiscount(gi.id);
					if (_price0 != 0) {
						gi.price = _price0; 
					}
				}
					
				gi.rest  = GoodsCursor.getDouble(9);				
				gi.measure_base_id  = GoodsCursor.getString(10);				
				gi.measure_base_descr = GoodsCursor.getString(11);
				gi.measure_base_factor = GoodsCursor.getDouble(12);
				gi.position = GoodsRef.size(); 
				GoodsRef.add(gi);
					
				if ((gi.isfolder == 1) & (recursive == true)) {
					GoodsGroupList.add(gi);						
					GetChildGoodsRefByGoodsIdNext (gi.id,true, true);	
				}
				
				GoodsCursor.moveToNext();
			}
			GoodsCursor.close();
		}
	}
	
	
	private int GetSortingMode () {
		
		int CurrentSortingMode = Integer.parseInt(MainGlobalModule.SettingsCollection.get("GoodsSorting")); 
		sel_sorting.setText(SortingItems[CurrentSortingMode]);
		return (CurrentSortingMode);
		
	}
	
	public void GetChildGoodsRefByGoodsId (String GoodsId,boolean Append, boolean recursive,boolean clearbefore,boolean SelectionToFirst) {					
		
		Cursor GoodsCursor = MainGlobalModule.GetGoodsRefCursorByParentId (GoodsId, PriceCategory, Firm, AccType, Department,GetSortingMode ());
		
		if (GoodsCursor.getCount()<1){
			GoodsCursor.close();
			return;
		}
		GoodsCursor.close();
		
		if (clearbefore) {
			GoodsRef.clear();	
		}		
		
		GoodsGroupList.clear();		
		GetChildGoodsRefByGoodsIdNext (GoodsId,Append, recursive);
		
		adap.notifyDataSetChanged();
		
		if (SelectionToFirst) {
			getListView().setSelection(0);
		}
				
		
		if (recursive==true & GoodsGroupList.size()>0) {			
			GoupArrayStrings = new String [GoodsGroupList.size()];
			for (int i=0;i<GoodsGroupList.size();i++) {
				GoupArrayStrings[i] = String.format("<%s> ", GoodsGroupList.get(i).descr); 
			}
			GroupGallery.setVisibility(View.VISIBLE);
			gadap = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, GoupArrayStrings);
			GroupGallery.setAdapter(gadap);			
		}
		else
		{			
			GroupGallery.setVisibility(View.GONE);
		}		
				
	}	
	
	public void SetGoodsRefToDefault () {
		
		GetChildGoodsRefByGoodsId (DefGoodsGroup,false,false,true,true);	
		
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		Ctx = this;
		
        requestWindowFeature(Window.FEATURE_NO_TITLE);            
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.goods_form);		
		
		actxLinear = (RelativeLayout)findViewById(R.id.linear);
		actxLinear.setVisibility(View.GONE);
		
		actxsetall = (ImageView)findViewById(R.id.ctxa_selall);
		actxsetall.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				for (GoodsRefItem gi:GoodsRef) {
					if (gi.isfolder != 1) {
						SelectedGoods.put(gi.id, gi);
					}					
				}
				adap.notifyDataSetChanged();				
			}
		});
		
		actxunsetall = (ImageView)findViewById(R.id.ctxa_unselall);
		actxunsetall.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				for (GoodsRefItem gi:GoodsRef) {
					if (gi.isfolder != 1) {
						SelectedGoods.remove(gi.id);
					}					
				}
				adap.notifyDataSetChanged();
			}
		});
		
		
		actxunsetcount = (ImageView)findViewById(R.id.ctxa_setcount);
		actxunsetcount.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent NumericPrompt = new Intent ();
				NumericPrompt.setClass(Ctx, Activity_NumericPrompt.class);
				NumericPrompt.putExtra("Numeric", 0);				
				startActivityForResult(NumericPrompt, IDR_NumericPromptCount);				
			}
		});
		
		actxundistrcount = (ImageView)findViewById(R.id.ctxa_dustrcount);
		actxundistrcount.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				Intent NumericPrompt = new Intent ();
				NumericPrompt.setClass(Ctx, Activity_NumericPrompt.class);
				NumericPrompt.putExtra("Numeric", 0);				
				startActivityForResult(NumericPrompt, IDR_NumericPromptDistr);				
			}
		});
		
		actxundfilter = (ImageView)findViewById(R.id.ctxa_filter); 
		actxundfilter.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				SelectedMode_Show ();
				ResetSelectMode ();
			}
		});
		
		actxundcancel = (ImageView)findViewById(R.id.ctxa_exit);
		actxundcancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				ResetSelectMode ();
				
			}
		});
		
		actxundistrcount.setVisibility(View.GONE);
		actxunsetcount.setVisibility(View.GONE);
		
		OrderSumLabel = (TextView)findViewById(R.id.OrderSumLabel);		
		DefGoodsGroup = MainGlobalModule.ConstantsCollection.get("DefGoodsGroup");
		
		order_root_iv = (ImageView)findViewById(R.id.order_root_iv);
		order_root_iv.setOnClickListener(order_root_iv_Click);
		order_root_iv.setOnLongClickListener(order_root_iv_LongClick);		
		
		order_tree_iv = (ImageView)findViewById(R.id.order_tree_iv);
		order_tree_iv.setOnClickListener(goods_tree_Click);
		
		order_AssortmentSelectOpen = (ImageView)findViewById(R.id.order_AssortmentSelectOpen);
		order_AssortmentSelectOpen.setOnClickListener(goods_assort_Click);
		
		presenter_btn = (ImageView)findViewById(R.id.presenter_btn);
		presenter_btn.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				StartGoodsImages();				
			}
		});
		
		order_barcode = (ImageView)findViewById(R.id.order_barcode);
		order_barcode.setOnClickListener(order_barcode_Click);		
		
		GoodsRef = MainGlobalModule.GoodsRef;
		
		sel_pricecategory = (Button)findViewById(R.id.sel_pricecategory);
		sel_pricecategory.setOnClickListener(sel_pricecategory_dialog);			
		
		sel_sorting = (Button)findViewById(R.id.sel_sorting);
		sel_sorting.setOnClickListener(sel_sorting_dialog);	
		
		Bundle DocExtra = getIntent().getExtras();
		
		SelectedGoods = new LinkedHashMap<String, GoodsRefItem>();
		
		if (DocExtra!=null) {
			
			GoodsRefRefresh = DocExtra.getBoolean("GoodsRefRefresh",true);	
			
			OrderSumLabel.setVisibility(View.VISIBLE);
			DocType = DocExtra.getInt("DocType");			
			SelectOnce = DocExtra.getBoolean("SelectOnce");
			
			DocumentClass = MainGlobalModule.DocumentClass;
			
			switch (DocType) {
			
			case MainGlobalModule.DocumentsType.Order:
				
				DocId = ((Documents_Order)DocumentClass).Head.id;
				Firm = ((Documents_Order)DocumentClass).Head.firms_id;
				AccType = ((Documents_Order)DocumentClass).Head.acctype;
				Department = ((Documents_Order)DocumentClass).Head.departments_id;
				Customer = ((Documents_Order)DocumentClass).Head.customers_id;
				PriceCategory = MainGlobalModule.GetCustomerPriceCategoy (Customer);
				
				OrderSalesCollection = ((Documents_Order)DocumentClass).SalesCollection;
				OrderAssortmentCollection = ((Documents_Order)DocumentClass).OrderAssortmentCollection;
				CustomerAssortmentCollection = ((Documents_Order)DocumentClass).CustomerAssortmentCollection;
				OrderDocLineCollection = ((Documents_Order)DocumentClass).DocLineCollection;
				
				OrderSumLabel.setText(String.format( "Сумма: %.2f",((Documents_Order) DocumentClass).Head.total_ordersum));
				
				OffersGoodsList =  ((Documents_Order)DocumentClass).OffersGoodsList;
				
				actxundistrcount.setVisibility(View.VISIBLE);
				actxunsetcount.setVisibility(View.VISIBLE);
				
				break;
				
			case MainGlobalModule.DocumentsType.Return:
			
				DocId = ((Documents_Return)DocumentClass).Head.id;
				Firm = ((Documents_Return)DocumentClass).Head.firms_id;
				AccType = ((Documents_Return)DocumentClass).Head.acctype;
				Department = ((Documents_Return)DocumentClass).Head.departments_id;
				Customer = ((Documents_Return)DocumentClass).Head.customers_id;
				PriceCategory = MainGlobalModule.GetCustomerPriceCategoy (Customer);
				
				OrderSumLabel.setText(String.format( "Сумма: %.2f",((Documents_Return) DocumentClass).Head.total_returnsum));
				break;
				
			default:
				break;
				
			}		
			
			GoodObject = new GoodRefObject (Customer);
			if (GoodObject.DiscountRef.size()>0) {
				DiscountsEnable = MainGlobalModule.ConstantsCollection.get("DiscountsEnable").equals("true");
			}
			else
			{
				DiscountsEnable = false;
			}
			
		}		
		
		else
		{
			GoodsRefRefresh = true;
			OrderSumLabel.setVisibility(View.INVISIBLE);
			DocType = 0;			
			DocId = "";
			Firm = MainGlobalModule.ConstantsCollection.get("DefFirm");
			AccType = MainGlobalModule.ConstantsCollection.get("DefAccType"); 
			Department = MainGlobalModule.ConstantsCollection.get("DefDepartment"); 			
			PriceCategory = MainGlobalModule.ConstantsCollection.get("DefPriceCategory");
			DiscountsEnable = false;
		}
				
			
		GroupGallery = (Gallery)findViewById(R.id.gallery1);
		GroupGallery.setOnItemSelectedListener(GalleryItemSelected);
		
		gadap = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, GoupArrayStrings);
		GroupGallery.setAdapter(gadap);
		
		adap = new EfficientAdapter(this);
		setListAdapter(adap);
		
		if (GoodsRefRefresh) {
			GetChildGoodsRefByGoodsId (DefGoodsGroup,false,false,true,true);
		}
		else
		{			
			GroupGallery.setVisibility(View.GONE);
			adap.notifyDataSetChanged();
			getListView().setSelection(0);			
		}		
		
		gds_backward = (ImageView)findViewById(R.id.gds_backward);
		gds_backward.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				finish ();	
			}
		});
		
		
		GetPriceCategoryCursor ();
		sel_pricecategory_refresh ();
		
		
		slidingDrawer = (SlidingDrawer)findViewById(R.id.slidingDrawer1);		
		searchprompt = (EditText)findViewById(R.id.searchprompt);
		
		searchbutton = (ImageView)findViewById(R.id.searchbutton);
		searchbutton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				FilterChoice("search");
				InputMethodManager imm = (InputMethodManager)Ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(searchprompt.getWindowToken(), 0);
				slidingDrawer.close();
				searchprompt.setText("");
			
			}
		});
		
		searchreset = (ImageView)findViewById(R.id.searchreset);
		searchreset.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {				
				InputMethodManager imm = (InputMethodManager)Ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(searchprompt.getWindowToken(), 0);
				slidingDrawer.close();
				searchprompt.setText("");
				GetChildGoodsRefByGoodsId (DefGoodsGroup,false,false,true,true);
			}
		});
		
		
		this.getListView().setOnItemLongClickListener(onListItemLongClick);	
		
		MainGlobalModule.setBackGround(getListView());
	    
		if (OrderAssortmentCollection!=null && OrderAssortmentCollection.size()>0) {
			FilterChoice ("TOP");
		}
		
	}	
	
	private OnClickListener sel_sorting_dialog = new OnClickListener() {		
		@Override
		public void onClick(View v) {	
			
			AlertDialog.Builder adb = new AlertDialog.Builder(Ctx);			
			adb.setItems(SortingItems,sel_sorting_dialog_select);
			adb.create().show();			
			
		}
	};	
	
	private DialogInterface.OnClickListener sel_sorting_dialog_select = new DialogInterface.OnClickListener() {		
		@Override
		public void onClick(DialogInterface dialog, int which) {			
									
			MainGlobalModule.SettingsCollection_Update ("GoodsSorting", String.valueOf(which));			
    		GetChildGoodsRefByGoodsId(GoodsRef.get(0).parentid,!Hierarchy,!Hierarchy,true,true);
    		
    		dialog.dismiss();
    		
		}
	}; 
	
	
	private OnClickListener sel_pricecategory_dialog = new OnClickListener() {		
		@Override
		public void onClick(View v) {
			
			if (DocumentClass==null) {			
				AlertDialog.Builder adb = new AlertDialog.Builder(Ctx);			
				adb.setCursor(PriceCategoryCursor, sel_pricecategory_dialog_select , "descr");			
				adb.create().show();
			}
			
		}
	};
	
	private void sel_pricecategory_refresh () {
		
		PriceCategoryCursor.moveToFirst();
		while (!PriceCategoryCursor.isAfterLast()) {
			if (PriceCategoryCursor.getString(0).equals(PriceCategory)) {
				sel_pricecategory.setText(PriceCategoryCursor.getString(1));
				break;
			}
			PriceCategoryCursor.moveToNext();
		}
		
	}
	
	private DialogInterface.OnClickListener sel_pricecategory_dialog_select = new DialogInterface.OnClickListener() {		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			
			
			PriceCategoryCursor.moveToPosition(which);
			PriceCategory = PriceCategoryCursor.getString(0);
			sel_pricecategory_refresh ();
			GetChildGoodsRefByGoodsId(GoodsRef.get(0).parentid,!Hierarchy,!Hierarchy,true,false);
    		dialog.dismiss();
    		
		}
	};	
	
	private OnItemSelectedListener GalleryItemSelected = new OnItemSelectedListener() {

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int position,long arg3) {
			 			
			getListView().setSelection(GoodsGroupList.get(position).position);
			
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

			
		}
				
	};
	
	
	private OnClickListener goods_tree_Click = new OnClickListener() {		
		@Override
		public void onClick(View v) {
			
			Intent GT = new Intent ();
			GT.setClass(Ctx, Activity_GoodsTree.class);			
			GoodsRefItem gi = adap.getItem(0);			
			GT.putExtra("CurrentFolder", gi.parentid);
			startActivityForResult(GT, IDR_GoodsTreeSelect);			
		}
	}; 

	private OnClickListener goods_assort_Click = new OnClickListener() {		
		@Override
		public void onClick(View v) {
			
			Assortments.clear();
			
			if (DocType == MainGlobalModule.DocumentsType.Order) {				
				if (OrderAssortmentCollection.size()>0) {
					Assortments.put("top", "ТОП ассортимент клиента");					
				}				
			}
			
			if (DocType!=0) {
				Assortments.put("customer", "Продаваемые товары по клиенту");
			}
			
			Assortments.put("goods", "Продаваемые товары");
		
			Cursor AssortmentsCursor = MainGlobalModule.DBE.rawQuery("select id,descr from xref_AssortmentsList where general = 1", null);
			if (AssortmentsCursor.getCount()>0) {
				AssortmentsCursor.moveToFirst();
				while (!AssortmentsCursor.isAfterLast()) {
					Assortments.put(AssortmentsCursor.getString(0),AssortmentsCursor.getString(1));
					AssortmentsCursor.moveToNext();
				}
			};
						
			AlertDialog.Builder adb = new AlertDialog.Builder(Ctx);
			adb.setItems(Assortments.values().toArray(new String [0]),AssortmentsItemChoice);			
			adb.create().show();			
			
		}
	}; 
	
	
	private void FilterChoice (String whichkey) {
		
		Cursor GoodsCursor = null;		
		
		if (whichkey.equals("customer")) {			
			GoodsCursor = MainGlobalModule.GetGoodsRefCursorBySalesTOPN(Customer, 0, PriceCategory,Firm,AccType,Department,GetSortingMode ());
		}		
					
		if (whichkey.equals("goods")) {
			GoodsCursor = MainGlobalModule.GetGoodsRefCursorBySalesTOPN(null, 20, PriceCategory,Firm,AccType,Department,GetSortingMode ());
		}
		
		if (whichkey.equals("search")) {
			if (searchprompt.getText().toString().length()>2) {
				GoodsCursor = MainGlobalModule.GetGoodsRefCursorByName(searchprompt.getText().toString(),PriceCategory,Firm,AccType,Department,GetSortingMode ());	
			}
			else
			{
				return;
			}				
		}		
		
		if (whichkey.equals("top")) {
			Cursor SimpleCursor = MainGlobalModule.DBE.rawQuery("select assortmentslist_id from xref_CustomersAssortments where customers_id = ?", new String [] {Customer});
			if (SimpleCursor.getCount()>0) {
				SimpleCursor.moveToFirst();
				String AssortmentListId = SimpleCursor.getString(0);
				GoodsCursor = MainGlobalModule.GetGoodsRefCursorByAssortmentId(AssortmentListId, PriceCategory, Firm, AccType, Department, GetSortingMode ());
			}					
		}
		
		if (GoodsCursor==null) {
			GoodsCursor = MainGlobalModule.GetGoodsRefCursorByAssortmentId(whichkey, PriceCategory, Firm, AccType, Department, GetSortingMode ());	
		}
		
		if (GoodsCursor!=null && GoodsCursor.getCount() > 0){
			
			GoodsRef.clear();
			GoodsCursor.moveToFirst();
			
			while (!GoodsCursor.isAfterLast()) {	
				
				GoodsRefItem gi = new GoodsRefItem ();
				
				gi.id = GoodsCursor.getString(0);
				gi.parentid = GoodsCursor.getString(1);
				gi.article = GoodsCursor.getString(2);
				gi.descr = GoodsCursor.getString(3);
				gi.isfolder = GoodsCursor.getInt(4);
				gi.weight = GoodsCursor.getDouble(5);
				gi.volume = GoodsCursor.getDouble(6);
				gi.minimum_order = GoodsCursor.getDouble(7);
				gi.price = GoodsCursor.getDouble(8);
				
				if (DiscountsEnable & gi.isfolder == 0) {
					double _price0 = GoodObject.GetGoodPriceByDiscount(gi.id);
					if (_price0 != 0) {
						gi.price = _price0; 
					}
				}
					
				gi.rest  = GoodsCursor.getDouble(9);				
				gi.measure_base_id  = GoodsCursor.getString(10);				
				gi.measure_base_descr = GoodsCursor.getString(11);
				gi.measure_base_factor = GoodsCursor.getDouble(12);
				
				if (GoodsCursor.getColumnCount()>=15) {
					gi.rule_factor = GoodsCursor.getDouble(13);
					gi.target = GoodsCursor.getDouble(14);
				};
				
				gi.position = GoodsRef.size();
				
				if (gi.isfolder==0) {
					GoodsRef.add(gi);	
				}						
				
				GoodsCursor.moveToNext();
			}
			GoodsCursor.close();				
			adap.notifyDataSetChanged();
			getListView().setSelection(0);
		}
		else
		{
			Toast.makeText(this, "Ничего не найдено !", Toast.LENGTH_LONG).show();
		}
		
	}
	
	
	private DialogInterface.OnClickListener AssortmentsItemChoice = new DialogInterface.OnClickListener() {		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			
			String whichkey = (String) Assortments.keySet().toArray()[which];
			FilterChoice (whichkey);
			
		}			
	};
	
	private OnClickListener order_root_iv_Click = new OnClickListener() {		
		@Override
		public void onClick(View v) {
			GoodsBackWard ();
		}
	}; 
	
	private OnLongClickListener order_root_iv_LongClick = new OnLongClickListener() {		
		@Override
		public boolean onLongClick(View v) {
			SetGoodsRefToDefault();
			return false;
		}
	}; 
	
	private OnClickListener order_barcode_Click = new OnClickListener() {		
		@Override
		public void onClick(View v) {			
			try {
				Intent intentX = new Intent("com.google.zxing.client.android.SCAN");    			
				intentX.putExtra("SCAN_MODE", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");        		
	    		startActivityForResult(intentX, IDR_Barcode);	
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}; 
	
	private OnItemLongClickListener onListItemLongClick = new OnItemLongClickListener() {
		@Override
		public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
				int position, long arg3) {
			
			GoodsRefItem gi = adap.getItem(position);
			if (gi.isfolder == 1) {				
				GetChildGoodsRefByGoodsId(gi.id, true, true,true,true);				
			}	
			else
			{
				if (!isSelectMode) {
					isSelectMode = true;
					actxLinear.setVisibility(View.VISIBLE);
					ProcessSGoodsSelection (gi);
				}
				adap.notifyDataSetChanged();
			}
			return true;	
		}
		
	};	
	
	
	private void InsertGoodsRefItemToOrderDoc (GoodsRefItem gi,double Count,boolean Add) {		
		
		if (DocType == MainGlobalModule.DocumentsType.Order) {
			DocLine docit = ((Documents_Order)DocumentClass).DocLineCollection.get(gi.id);			
			if (docit!=null) {
				
				Count = Add? Count+docit.ordervalue:Count;
				
				((Documents_Order)DocumentClass).Line.id = docit.id;
				((Documents_Order)DocumentClass).Line.hdoc_id = docit.hdoc_id;
				((Documents_Order)DocumentClass).Line.goods_id = gi.id;
				((Documents_Order)DocumentClass).Line.goods_descr = gi.descr;  
				((Documents_Order)DocumentClass).Line.factor = gi.measure_base_factor;
				((Documents_Order)DocumentClass).Line.goods_feature_id = "";
				((Documents_Order)DocumentClass).Line.goods_measures_id = gi.measure_base_id;
				((Documents_Order)DocumentClass).Line.goods_measures_descr = gi.measure_base_descr;
				((Documents_Order)DocumentClass).Line.price = gi.price;				
								
				((Documents_Order)DocumentClass).Line.ordervalue = Count;
				
				((Documents_Order)DocumentClass).Line.restvalue = docit.restvalue;
				((Documents_Order)DocumentClass).Line.order_sum = Count * gi.price * gi.measure_base_factor;
			}			
			else {
				((Documents_Order)DocumentClass).Line.id = UUID.randomUUID().toString().toUpperCase();
				((Documents_Order)DocumentClass).Line.hdoc_id = ((Documents_Order)DocumentClass).Head.id;
				((Documents_Order)DocumentClass).Line.goods_id = gi.id;
				((Documents_Order)DocumentClass).Line.goods_descr = gi.descr;  
				((Documents_Order)DocumentClass).Line.factor = gi.measure_base_factor;
				((Documents_Order)DocumentClass).Line.goods_feature_id = "";
				((Documents_Order)DocumentClass).Line.goods_measures_id = gi.measure_base_id;
				((Documents_Order)DocumentClass).Line.goods_measures_descr = gi.measure_base_descr;
				((Documents_Order)DocumentClass).Line.price = gi.price;
				((Documents_Order)DocumentClass).Line.ordervalue = Count;			
				((Documents_Order)DocumentClass).Line.restvalue = 0;
				((Documents_Order)DocumentClass).Line.order_sum = Count * gi.price * gi.measure_base_factor;
			}			
			((Documents_Order)DocumentClass).InsertUpdateLine();	
		}
		
	}
	
	private void SelectedMode_SetCount (double Count) {
		
	
		if (Count>0) {
			Iterator<Entry<String,GoodsRefItem>> it = SelectedGoods.entrySet().iterator();
			while (it.hasNext()) {
				Entry<String,GoodsRefItem> en = it.next();
				InsertGoodsRefItemToOrderDoc (en.getValue(),Count,false);
			}				
		}
		
		ResetSelectMode ();	
		
	}
	
	private void SelectedMode_SetDistr (double Count) {
		
		if (Count>0) {
			int DistCount = (int)Count/SelectedGoods.size();
			int RestCount = (int)Count-(DistCount*SelectedGoods.size());  
			
			Iterator<Entry<String,GoodsRefItem>> it0 = SelectedGoods.entrySet().iterator();
			while (it0.hasNext()) {
				Entry<String,GoodsRefItem> en = it0.next();
				InsertGoodsRefItemToOrderDoc (en.getValue(),DistCount,false);
			}
			
			Iterator<Entry<String,GoodsRefItem>> it1 = SelectedGoods.entrySet().iterator();
			while (it1.hasNext()&RestCount>0) {
				Entry<String,GoodsRefItem> en = it1.next();
				InsertGoodsRefItemToOrderDoc (en.getValue(),1,true);
				RestCount--;
			}				
		}
		
		ResetSelectMode ();	
		
	}
	
	private void ResetSelectMode () {
		isSelectMode = false;
		SelectedGoods.clear();
		actxLinear.setVisibility(View.GONE);
		adap.notifyDataSetChanged();	
	}
	
	private void SelectedMode_Show () {
		
		GroupGallery.setVisibility(View.GONE);
		GoodsRef.clear();
		
		Iterator<Entry<String,GoodsRefItem>> it = SelectedGoods.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String,GoodsRefItem> en = it.next();
			GoodsRef.add(en.getValue());	
		}	
		
	}
	
	private void ProcessSGoodsSelection (GoodsRefItem gi) {
		
		if (isSelectMode) {
			if (SelectedGoods.containsKey(gi.id)) {
				SelectedGoods.remove(gi.id);
			}
			else
			{
				SelectedGoods.put(gi.id, gi);
			}
			adap.notifyDataSetChanged();
		}
		
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
		vb.vibrate(30);
		
		GoodsRefItem gi = adap.getItem(position);
		LastItem = gi.id;
				
		
		if (gi.isfolder == 1){
			if (Hierarchy==true) {
				GetChildGoodsRefByGoodsId(gi.id, false,false,true,true);				
			}	
		}
		else {
					
			
			switch (DocType) {
			
				case MainGlobalModule.DocumentsType.Order:
				
					if (MainGlobalModule.ExistsOffersByGoodsId ( ((Documents_Order)DocumentClass).Head.id,GoodsRef.get(position).id)) {					
					
						Toast.makeText(this, "Товар использован в акции, используйте подбор по акции !", Toast.LENGTH_LONG).show();						
					
					}
					else
					{
						if (isSelectMode) {
							ProcessSGoodsSelection (gi);
						}
						else {
							Intent OrderPrompt = new Intent ();				 
							OrderPrompt.setClass(Ctx,Activity_OrderGoodsPrompt.class);
							OrderPrompt.putExtra("GoodsRefPosition", position);				 
							startActivityForResult(OrderPrompt, IDR_OrderGoodsPromptSelect);	
						}						
					}
					
					break;
					
				case MainGlobalModule.DocumentsType.Return:								
					
					if (isSelectMode) {
						ProcessSGoodsSelection (gi);
					}
					else {
						Intent ReturnPrompt = new Intent ();				 
						ReturnPrompt.setClass(Ctx,Activity_ReturnGoodsPrompt.class);
						ReturnPrompt.putExtra("GoodsRefPosition", position);
						startActivityForResult(ReturnPrompt, IDR_ReturnGoodsPromptSelect);
					}
					break;
					
				default:
					ProcessSGoodsSelection (gi);
					break;
				}				
		}		
				
	  }
	
	public class EfficientAdapter extends BaseAdapter  {
		
		private LayoutInflater mInflater;
		public Context context;		
		
		
		public EfficientAdapter(Context context) {
			mInflater = LayoutInflater.from(context);
			this.context = context;
		}
		 
		public View getView(final int position, View convertView, ViewGroup parent) {	
			
			ViewHolder holder;
			
			boolean CustomerTOPAssortment = false;
			boolean CustomerAssortment = false;
			boolean CustomerSalesAssortment = false;
			
			Documents_Order.DocLine DocLine = null;
			
			if (convertView == null) {			
				convertView = mInflater.inflate(R.layout.goods_form_list, null);
			}
			
			holder = new ViewHolder();
		
			holder.textLine = (TextView)convertView.findViewById(R.id.textLine);
			holder.imageLine = (ImageView)convertView.findViewById(R.id.folderImageLine);			
			holder.GoodsList_GoodsPrice = (TextView)convertView.findViewById(R.id.GoodsList_GoodsPrice);
			holder.GoodsList_GoodsRest = (TextView)convertView.findViewById(R.id.GoodsList_GoodsRest);
			holder.GoodsList_DocRest = (TextView)convertView.findViewById(R.id.GoodsList_DocRest);
			holder.GoodsList_DocOrder = (TextView)convertView.findViewById(R.id.GoodsList_DocOrder);			
			holder.GoodsList_DocRestMeasure = (TextView)convertView.findViewById(R.id.GL_DocRestMeasure);
			holder.GoodsList_DocOrderMeasure = (TextView)convertView.findViewById(R.id.GL_DocOrderMeasure);
			
			holder.GoodsList_GoodsBaseMeasure = (TextView)convertView.findViewById(R.id.GL_GoodsBaseMeasure);
			
			GoodsRefItem gi = getItem(position);
			
			holder.textLine.setTextColor(Color.WHITE);			
			
			holder.GoodsList_GoodsBaseMeasure.setTextColor(Color.WHITE);
			holder.GoodsList_GoodsPrice.setTextColor(Color.WHITE);
			holder.GoodsList_GoodsRest.setTextColor(Color.WHITE);
			
			holder.GoodsList_DocRest.setTextColor(Color.WHITE);
			holder.GoodsList_DocOrder.setTextColor(Color.WHITE);
			
					
			holder.textLine.setText(gi.descr);
			
			if (gi.isfolder == 1) {
				
					holder.imageLine.setImageResource(R.drawable.ic_goodsfolder);
					holder.imageLine.setVisibility(ImageButton.VISIBLE);
				
					holder.GoodsList_GoodsPrice.setText("");
					holder.GoodsList_GoodsRest.setText("");				
					
					holder.GoodsList_DocRest.setText("");
					holder.GoodsList_DocOrder.setText("");
					holder.GoodsList_DocRestMeasure.setText("");
					holder.GoodsList_DocOrderMeasure.setText("");
					
					holder.GoodsList_GoodsBaseMeasure.setText("");
				
					if (!(OffersGoodsList==null)) {
						if (OffersGoodsList.contains(gi.id)) {
							holder.textLine.setTextColor(Color.MAGENTA);
						}
					}
					
				}
			
			else {
				
				if (isSelectMode ) {
					holder.imageLine.setVisibility(ImageButton.VISIBLE);
					if (SelectedGoods.containsKey(gi.id)){
						holder.imageLine.setImageResource(android.R.drawable.checkbox_on_background);							
					}
					else
					{
						holder.imageLine.setImageResource(android.R.drawable.checkbox_off_background);							
					}
				}
				else {
					holder.imageLine.setImageResource(R.drawable.ic_goodselement);
					holder.imageLine.setVisibility(ImageButton.INVISIBLE);						
				}
				
				holder.GoodsList_GoodsPrice.setText("ц.".concat(String.format("%.2f",gi.price*gi.measure_base_factor)));
				
				holder.GoodsList_GoodsBaseMeasure.setText(gi.measure_base_descr);
				
				double DocLastOrder = 0;
				double DocLastRest = 0;
				double DocRest = 0;
				double DocOrder = 0;
				
				if (DocType == MainGlobalModule.DocumentsType.Order){
					
					CustomerTOPAssortment = OrderAssortmentCollection.containsKey(gi.id);
					CustomerAssortment = CustomerAssortmentCollection.containsKey(gi.id);
					CustomerSalesAssortment = OrderSalesCollection.containsKey(gi.id);
					
					DocLine = OrderDocLineCollection.get(gi.id);
					if (DocLine!=null){						
						DocOrder = DocLine.ordervalue; 
						DocRest = DocLine.restvalue;
					}
					
				}
				
										
					if (DocRest > 0) {
						holder.GoodsList_DocRest.setText(String.valueOf(DocRest));
						holder.GoodsList_DocRest.setTextColor(Color.CYAN);
						holder.GoodsList_DocRestMeasure.setText(String.format("%s(%.1f)",gi.measure_base_descr,gi.measure_base_factor));
						holder.GoodsList_DocRestMeasure.setTextColor(Color.CYAN);
					}
					else
					{
						holder.GoodsList_DocRest.setText("");
						holder.GoodsList_DocRest.setTextColor(Color.DKGRAY);
						holder.GoodsList_DocRestMeasure.setText("");
						holder.GoodsList_DocRestMeasure.setTextColor(Color.DKGRAY);
					}
					
					
					if (DocOrder > 0) {						
						holder.GoodsList_DocOrder.setText(String.valueOf(DocOrder));
						holder.GoodsList_DocOrder.setTextColor(Color.GREEN);		
						holder.GoodsList_DocOrderMeasure.setText(String.format("%s(%.1f)",DocLine.goods_measures_descr,DocLine.factor));
						holder.GoodsList_DocOrderMeasure.setTextColor(Color.GREEN);
					}
					else
					{
						holder.GoodsList_DocOrder.setText("");
						holder.GoodsList_DocOrder.setTextColor(Color.DKGRAY);
						holder.GoodsList_DocOrderMeasure.setText("");
						holder.GoodsList_DocOrderMeasure.setTextColor(Color.DKGRAY);
					}				
					
					if (CustomerAssortment){
						holder.textLine.setTextColor(Color.rgb(0xff, 0x8c, 0x00));
					}					

					if (CustomerSalesAssortment) {
						holder.textLine.setTextColor(Color.YELLOW);
					}
					
					if (CustomerTOPAssortment){
						holder.textLine.setTextColor(Color.RED);
					}					

					if (!(OffersGoodsList==null)) {
						if (OffersGoodsList.contains(gi.id)) {							
							holder.GoodsList_GoodsBaseMeasure.setTextColor(Color.MAGENTA);
							holder.GoodsList_GoodsRest.setTextColor(Color.MAGENTA);						
							holder.GoodsList_GoodsPrice.setTextColor(Color.MAGENTA);
						}
					}					
					
					
					if (gi.rest<=0) {						
						holder.textLine.setTextColor(Color.DKGRAY);
						holder.GoodsList_GoodsBaseMeasure.setTextColor(Color.DKGRAY);						
						holder.GoodsList_GoodsRest.setText("оc.:".concat("Нет"));
						holder.GoodsList_GoodsRest.setTextColor(Color.DKGRAY);						
						holder.GoodsList_GoodsPrice.setTextColor(Color.DKGRAY);						
					}
					else {
						holder.GoodsList_GoodsRest.setText("ос.:".concat(String.format("%.1f",gi.rest/gi.measure_base_factor)));
					}			
					
				}
			
			    	
			if (LastItem.equals(gi.id)) {
				convertView.setBackgroundColor(Color.GRAY);
			}
			else {
				convertView.setBackgroundColor(Color.TRANSPARENT);
			}
			
			return convertView;
		
		}
		 
		class ViewHolder {
			
			TextView textLine;		
			ImageView imageLine;
			
			TextView GoodsList_GoodsPrice;
			TextView GoodsList_GoodsRest;
			
			TextView GoodsList_GoodsBaseMeasure;
						
			TextView GoodsList_DocRest;
			TextView GoodsList_DocOrder;						
			
			TextView GoodsList_DocRestMeasure;
			TextView GoodsList_DocOrderMeasure;
			
			
		}
		 
				 
		@Override
		public long getItemId(int position) {
			return 0;
		}
		 
		@Override
		public int getCount() {
			return GoodsRef.size();
		}
		 
		@Override
		public GoodsRefItem getItem(int position) {
			
			return GoodsRef.get(position);
		}
	
	}
	
	private void GoodsBackWard () {
		
		GoodsRefItem gi = adap.getItem(0);
		if (gi.parentid.equals(DefGoodsGroup)==true){
    		if (DocType==0) {
    			finish ();	
    		};    	    	
		}
		else {
			Hierarchy = true;
			String ParentId = gi.parentid;
			LastItem = ParentId;
			GetChildGoodsRefByGoodsId(GetParent(gi.parentid), false,false,true,true);			
			int indx = 0;
			for (GoodsRefItem it : GoodsRef) {				 
				if (it.id.equals(ParentId)) {					
					this.getListView().setSelection(indx);					
					break;
				}
				indx ++;
			}			
			
		}    			
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {		
		
		switch (keyCode){
		
    		case KeyEvent.KEYCODE_BACK:
    			
    			GoodsBackWard ();
    			return false;
    			
    		case KeyEvent.KEYCODE_SEARCH:
    			
				StartGoodsImages ();    			
    			return true;
    		
    	}	
		return super.onKeyDown(keyCode, event);
	}
		
	private void StartGoodsImages () {
		
		int itemscount = 0;
		for (GoodsRefItem it : GoodsRef){			
			if (it.isfolder!=1) {
				itemscount ++;
			}			
		}
		
		if (itemscount>0) {
			Intent GoodsImagesIntent = new Intent();
			GoodsImagesIntent.setClass(Ctx,MainGoodsImagesActivity.class);				
	    	startActivityForResult (GoodsImagesIntent,IDR_GoodsImagesSelect);	
		}		    			   
    	
	}
	

	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
			
			 switch(requestCode) {
			 
			    case IDR_OrderGoodsPromptSelect:
			    	
			    	 if (SelectOnce == true) {
					   		finish ();	
					   	}
			    	 else
			    	 {
			    		 OrderSumLabel.setText(String.format( "Сумма: %.2f",((Documents_Order) DocumentClass).Head.total_ordersum));	 
			    	 }
		    	
			    	adap.notifyDataSetChanged();			    				    	 
			    	break;
			    	
			    case IDR_ReturnGoodsPromptSelect:
			    	
			    	adap.notifyDataSetChanged();			    	
			    	break;
			    	
			    case IDR_Barcode:
			    	
			    	
			    	String contents="";
			    	if (resultCode == RESULT_OK) {
			    		contents = data.getStringExtra("SCAN_RESULT");
			    		Cursor GoodsCursor = MainGlobalModule.GetGoodsRefCursorByBarcode(contents, PriceCategory, Firm, AccType, Department);
			    		
			    		if (GoodsCursor.getCount()>0) { 
			    		
			    			GoodsRef.clear();
			    			
			    			GoodsCursor.moveToFirst();
			    			GoodsRefItem gi = new GoodsRefItem ();
			    			gi.id = GoodsCursor.getString(0);
			    			gi.parentid = GoodsCursor.getString(1);
			    			gi.article = GoodsCursor.getString(2);
			    			gi.descr = GoodsCursor.getString(3);
			    			gi.isfolder = GoodsCursor.getInt(4);
			    			gi.weight = GoodsCursor.getDouble(5);
			    			gi.volume = GoodsCursor.getDouble(6);
			    			gi.minimum_order = GoodsCursor.getDouble(7);
			    			gi.price = GoodsCursor.getDouble(8);
						
			    			if (DiscountsEnable & gi.isfolder == 0) {
			    				double _price0 = GoodObject.GetGoodPriceByDiscount(gi.id);
			    				if (_price0 != 0) {
			    					gi.price = _price0; 
			    				}
			    			}
							
			    			gi.rest  = GoodsCursor.getDouble(9);				
			    			gi.measure_base_id  = GoodsCursor.getString(10);				
			    			gi.measure_base_descr = GoodsCursor.getString(11);
			    			gi.measure_base_factor = GoodsCursor.getDouble(12);
			    			gi.position = 0; 
			    			GoodsRef.add(gi);
			    			
			    			adap.notifyDataSetChanged();
			    			
			    		}			    		
			    
			    		else {
			    			Toast xtoast = Toast.makeText(this, String.format("товар со штрихкодом %s не найден", contents), 10);
			    			xtoast.show();
			    		}						    			    	        
			    	}	
			    	break;
			    case IDR_GoodsTreeSelect:
			    	if (resultCode == RESULT_OK) {
			    		String GoodsTreeId = data.getStringExtra("GoodsTreeId");
			    		Hierarchy = data.getBooleanExtra("Hierarchy", false);
			    		GetChildGoodsRefByGoodsId(GoodsTreeId,!Hierarchy,!Hierarchy,true,true);			    		
			    		
			    	}
			    	break;			    	
			    case IDR_GoodsImagesSelect:
			    {
			    	adap.notifyDataSetChanged();
			    	//getListView().setSelection(data.getIntExtra("GoodsRefPosition",0));
			    	break;
			    }
			    
			    case IDR_NumericPromptCount: {	
			    	if (data!=null) {
			    		SelectedMode_SetCount (data.getDoubleExtra("NumericValue", 0));	
			    	}
			    	break;
			    }
			    
			    case IDR_NumericPromptDistr: {
			    	if (data!=null) {
			    		SelectedMode_SetDistr (data.getDoubleExtra("NumericValue", 0));	
			    	}			    	
			    	break;
			    }
			    
			 }
			    	
		};	

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}	
		
	
	
}